<% include ../header.ejs %>

<link rel="stylesheet" href="/lib/datetimepicker/css/amazeui.datetimepicker.css"/>

<script src="/lib/datetimepicker/js/amazeui.datetimepicker.min.js"></script>
<script src="/lib/datetimepicker/js/locales/amazeui.datetimepicker.zh-CN.js"></script>

<header data-am-widget="header" data-am-sticky class="am-header am-header-default" id="appTemplates-Nav">
    <div class="am-header-left am-header-nav">
        <a href='javascript:history.go(-1)' class="">
            <img class="am-header-icon-custom" src="data:image/svg+xml;charset&#x3D;utf-8,&lt;svg xmlns&#x3D;&quot;http://www.w3.org/2000/svg&quot; viewBox&#x3D;&quot;0 0 12 20&quot;&gt;&lt;path d&#x3D;&quot;M10,0l2,2l-8,8l8,8l-2,2L0,10L10,0z&quot; fill&#x3D;&quot;%23fff&quot;/&gt;&lt;/svg&gt;" alt=""/>
        </a>
    </div>

    <h1 class="am-header-title">
        <a href="#title-link" class="" id="Typeface-whitecolor">编辑调研</a>
    </h1>

    <div class="am-header-right am-header-nav">
        <a onclick="javascript:$('#save').click();" class="" data-am-modal="{target: '#modal-type-add', closeViaDimmer: 0, width: 240, height: 260}">保存</a>
    </div>
</header>

<form name="editsurvey" class="am-form" method="post" action="edit" data-am-validator>
    <fieldset>
        <input type="hidden" name="rowId" value="<%=info.obj.rowId%>"/>
        <div class="am-form-group" style="margin-top:5px;">
            <label for="doc-vld-name">开始时间:</label>
            <div class="am-input-group date" id="start_datetime" data-date-format="yyyy-mm-dd hh:ii">
                <input name="startTime" id="startTime" type="text" placeholder="开始时间" class="am-form-field" value="<%=moment(info.obj.startTime).format('YYYY-MM-DD hh:mm')%>" readonly required>
                <span class="am-input-group-label add-on"><i class="icon-th am-icon-calendar"></i></span>
            </div>
        </div>

        <div class="am-form-group" style="margin-top:5px;">
            <label for="doc-vld-name">结束时间:</label>
            <div class="am-input-group date" id="end_datetime" data-date-format="yyyy-mm-dd hh:ii">
                <input name="finishTime" id="finishTime" type="text" placeholder="结束时间" class="am-form-field" value="<%=moment(info.obj.finishTime).format('YYYY-MM-DD hh:mm')%>" readonly required>
                <span class="am-input-group-label add-on"><i class="icon-th am-icon-calendar"></i></span>
            </div>
        </div>

        <div class="am-form-group" style="margin-top:5px;">
            <label for="doc-vld-name">券商:</label>
            <select name="seller" data-am-selected="{btnWidth:'100%'}" placeholder="券商" required>
                <% seller.obj.forEach(function (data, index) {%>
                <option value="<%=data.rowId%>" <%if(data.rowId==info.obj.seller.rowId){%>selected<%}%>><%=data.name%></option>
                <% })%>
            </select>
        </div>

        <div class="am-form-group" style="margin-top:5px;">
            <label for="doc-vld-name">行业:</label>
            <select name="industry" data-am-selected="{btnWidth:'100%'}" placeholder="选择行业" required>
                <% industry.obj.forEach(function (data, index) {%>
                <option value="<%=data.rowId%>" <%if(data.rowId==info.obj.industry.rowId){%>selected<%}%>><%=data.industryName%></option>
                <% })%>
            </select>
        </div>


        <div>
            <label for="doc-vld-name">类型:</label>
            <div class="am-cf" style="width:214px;margin-top:5px;">
                <div id="schedule_type_switch" class="am-btn-group" data-am-button>
                    <label class="am-btn am-btn-secondary">
                        <input type="radio" name="survey_type" value="industry" id="btn_survey" <%if(info.obj.type=='行业调研'){%>checked<%}%> needsclick>行业调研</input>
                    </label>
                    <label class="am-btn am-btn-secondary">
                        <input type="radio" name="survey_type" value="company" id="btn_roadshow" <%if(info.obj.type=='公司调研'){%>checked<%}%> needsclick>公司调研</input>
                    </label>
                </div>
                <input type="hidden" id="type_name" name="type_name" value="<%=info.obj.type%>"/>
            </div>
        </div>

        <div id="company_name_container" class="am-form-group" <%if(info.obj.type=='行业调研'){%>style="display: none; margin-top: 5px;"<%} else {%>style="margin-top: 5px;"<%}%>>
            <select class="company-data-ajax" style="width: 100%" id="company_name" name="company_name">
                <%if(info.obj.type!='行业调研'){%><option value="<%=info.obj.company.rowId%>"><%=info.obj.company.name%></option><%}%>
            </select>
        </div>


        <div style="margin-top:5px;margin-bottom: 0rem;">
            <textarea name="survey_desc" id="survey_desc" rows="5" id="doc-ta-1" placeholder="请输入调研内容"><%=info.obj.content%></textarea>
        </div>

        <div style="margin-top:5px;">
            <label for="doc-vld-name">范围:</label>
            <div style="width:280px;">
                <div id="schedule_type_switch" class="am-btn-group" data-am-button>
                    <label class="am-btn am-btn-secondary">
                        <input type="radio" name="range" value="onebyone" <%if(info.obj.range=='一对一'){%>checked<%}%> needsclick>一对一</input>
                    </label>
                    <label class="am-btn am-btn-secondary">
                        <input type="radio" name="range" value="srange" <%if(info.obj.range=='一对小范围'){%>checked<%}%> needsclick>一对小范围</input>
                    </label>
                    <label class="am-btn am-btn-secondary">
                        <input type="radio" name="range" value="brange" <%if(info.obj.range=='大范围'){%>checked<%}%> needsclick>大范围</input>
                    </label>
                    <input type="hidden" id="range_type" name="range_type" value="<%=info.obj.range%>"/>
                </div>
            </div>
        </div>

        <div style="margin-top:10px;">
            <label for="doc-vld-name">地址:</label>
            <div  style="margin-top:5px;height:37px;">
                <div class="am-u-sm-6" style="padding-left: 0rem;">
                    <select name="province" id="province" data-am-selected="{btnWidth:'100%'}" placeholder="选择省份">
                    </select>
                </div>
                <div class="am-u-sm-6" style="padding-left: 0rem;padding-right: 0rem;">
                    <select name="city" id="city" data-am-selected="{btnWidth:'100%'}" placeholder="选择城市">
                    </select>
                </div>
            </div>
        </div>
        <div class="am-form-group" style="margin-top:5px;margin-bottom: 0rem;">
            <textarea id="address" name="address" rows="5" placeholder="请输入调研地址"><%=info.obj.addr%></textarea>
        </div>

        <!--<div class="am-form-group" style="margin-top:5px;margin-bottom: 0rem;">-->
        <!--<input id="contact" name="contact" type="text" placeholder="请输入联系方式" value="<%=info.obj.contactName%>"></input>-->
        <!--</div>-->

        <div class="am-form-group" style="margin-top:5px;margin-bottom: 0rem;">
            <label for="doc-vld-name">联系电话:</label>
            <input id="phone" name="phone" type="text" placeholder="请输入联系电话" value="<%=info.obj.contact%>"></input>
        </div>

        <div  class="am-form-group" style="margin-top: 5px;">
            <label for="doc-vld-name">预约人:</label>
            <select multiple data-am-selected="{btnWidth: '100%'}" placeholder="请选择人员" id="person_name" name="person_name">
                <% person.obj.forEach(function (data, index) {%>
                <option value="<%=data.rowId%>"  <% info.obj.userjoinList.forEach(function (data_userinfo, index) {%><%if(data.rowId==data_userinfo.userId.rowId){%>selected<%}%><% })%> ><%=data.name%></option>
                <% })%>
            </select>
        </div>
        <button class="am-btn am-btn-secondary" type="submit" id="save" style="visibility:hidden">保存</button>
    </fieldset>
</form>

<form name="delsurvey" id="delsurvey" class="am-form" method="post" action="delete">
    <fieldset>
        <input type="hidden" name="rowId" value="<%=info.obj.rowId%>"/>
        <button id="btnDelSurvey" type="button" class="am-btn am-btn-danger am-btn-block">删除</button>
    </fieldset>

    <div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">
        <div class="am-modal-dialog">
            <div class="am-modal-hd">删除日程</div>
            <div class="am-modal-bd">
                确定要删除这条记录吗？
            </div>
            <div class="am-modal-footer">
                <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                <span class="am-modal-btn" data-am-modal-confirm>确定</span>
            </div>
        </div>
    </div>
</form>

<script src="/javascripts/app/schedule/survey_edit.js"></script>
<script type="text/javascript">
    $(".company-data-ajax").select2({
        ajax: {
            url: "../../../api/dicStock/getStockList",
            dataType: 'json',
            delay: 250,
            data: function (params) {
                return {
                    name: params.term
                };
            },
            processResults: function (data, params) {
                params.page = params.page || 1;
                var newdata = $.map(data.obj, function (obj) {
                    obj.id = obj.id || obj.rowId; // replace pk with your identifier
                    obj.text = obj.text ||obj.stockCode+" "+ obj.name;
                    return obj;
                });

                return {
                    results: newdata,
                    pagination: {
                        more: (params.page * 30) < data.total_count
                    }
                };
            },
            cache: true
        },
        placeholder: "请选择上市公司",
        escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
        minimumInputLength: 2
    });

    //++++++++++++++++限制开始时间大于当前,结束时间大于开始时间
    $(function() {

        $('#start_datetime').datetimepicker('setStartDate', new Date());
        $('#end_datetime').datetimepicker('setStartDate',new Date());

        $("#startTime").on("change",function(event){
            var strTime=$("#startTime").val();
//            var date=new Date(Date.parse(strTime));
            var date = new Date(Date.parse(strTime.replace(/-/g, "/")));
            var endTime=new Date(date.setHours(date.getHours()+1));
            var strEndTime=dateToStr(endTime);
            $("#finishTime").val(strEndTime);



            $('#end_datetime').datetimepicker('setStartDate',strEndTime);
        });

    });

    function dateToStr(date){
        var dd = date.getDate() < 10 ? "0" + date.getDate() : date.getDate().toString();
        var month=date.getMonth()+1;
        var mmm = month<10? "0" +month: month.toString()
        var yyyy = date.getFullYear().toString();
        var hour=date.getHours()<10 ? "0"+date.getHours():date.getHours().toString();
        var min=date.getMinutes()<10?"0"+date.getMinutes():date.getMinutes().toString();
        return yyyy+"-"+mmm+"-"+dd+" "+hour+":"+min;
    }
</script>

<% include ../footer.ejs %>
